using NUnit.Framework;
using Rhino.Mocks;
using TestAssemblyInterfaces;
using ILog = log4net.ILog;

namespace LoggingMagic.Tests.Integration.StaticFieldTests
{
    [TestFixture]
    public class SetterGetterTests
    {

        private ITestClass _target;
        private ILog _logger;

        private Initializer _initializer;
        [TearDown]
        public void Dispose()
        {
            _initializer.Dispose();
        }

        public void Setup(bool logSetters, bool logGetters)
        {
            _initializer = new Initializer(new LoggingTask { LogGetters = logGetters ? "1" : "0", LogSetters = logSetters ? "1" : "0" });

            _logger = MockRepository.GenerateStrictMock<ILog>();
            Initializer.SetLogger(_logger);

            _logger.Expect(x => x.Info("TestClass..ctor - Entering"));

            _target = Initializer.GetTestAssemblyInstance();
        }

        [Test]
        public void Setter_Logged()
        {
            Setup(true, false);

            _logger.Expect(x => x.Info("TestClass.set_TestProperty - Entering"));
            _target.TestProperty = 4;

            _logger.VerifyAllExpectations();
        }

        [Test]
        public void Setter_NotLogged()
        {
            Setup(false, false);

            _target.TestProperty = 4;
        }

        [Test]
        public void Getter_NotLogged()
        {
            Setup(false, false);

            var zxc = _target.TestProperty;
        }

        [Test]
        public void Getter_Logged()
        {
            Setup(false, true);

            _logger.Expect(x => x.Info("TestClass.get_TestProperty - Entering"));
            var zxc = _target.TestProperty;

            _logger.VerifyAllExpectations();
        }


        [Test]
        public void SetterWithParams_Logged()
        {
            Setup(true, false);

            _logger.Expect(x => x.InfoFormat("TestClass.set_TestPropertyWithParams - Entering('{0}')", new object[] { 4 }));
            _target.TestPropertyWithParams = 4;

            _logger.VerifyAllExpectations();
        }

    }
}